package com.gitee.l0km.thrift.swift2thrift.generator;

import com.gitee.l0km.codegen.annotations.CodegenInvalidValue;
import com.gitee.l0km.codegen.annotations.CodegenRequired;
import com.gitee.l0km.xthrift.base.metadata.DecoratorThriftFieldMetadata;
import com.gitee.l0km.xthrift.base.metadata.ThriftFieldMetadataUtil;
import com.google.common.base.Predicate;
import com.google.common.reflect.TypeToken;

public class CodegenRequirednessFilter implements Predicate<DecoratorThriftFieldMetadata> {

	public CodegenRequirednessFilter() {
	}

	 @Override
	 public boolean apply(DecoratorThriftFieldMetadata input) {
		 Class<?> javaType = TypeToken.of(input.getThriftType().getJavaType()).getRawType();
		 if(javaType.isPrimitive() || javaType.isEnum()){
			 return true;
		 } 
		 if(input.isCanPrimitive() && null !=ThriftFieldMetadataUtil.extractFieldAnnotation(input,CodegenInvalidValue.class)){
			 return true;
		 }
//		 CodegenRequired ann = ThriftFieldMetadataUtil.extractFieldAnnotation(input,CodegenRequired.class);
//		 if(null != ann){
//			 return ann.value();
//		 }
		 return false;
	 }

}
